#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <cstring>
using namespace std;
void handle(int signo)
{
    sigset_t set;
    cout << "我是被捕捉的" << signo << "号信号" << endl;
    int cnt = 30;
    while (cnt--)
    {
        sigpending(&set);
        for (int i = 1; i <= 31; i++)
        {
            // 打印一下对应的pending表
            if (sigismember(&set, i))
            {
                cout << 1;
            }
            else
                cout << 0;
        }
        cout<<endl;
        sleep(1);
    }
}
int main()
{
    cout << "pid:" << getpid() << endl;
    sigset_t set;
    sigaddset(&set, 3);
    sigaddset(&set, 4);
    sigaddset(&set, 5);
    struct sigaction act;
    struct sigaction oact;
    memset(&act, 0, sizeof(act));
    act.sa_handler = handle;
    act.sa_mask = set; // 在执行2号命令的处理函数时，同时也屏蔽掉3,4,5号信号
    memset(&oact, 0, sizeof(oact));
    sigaction(2, &act, &oact);
    while (1)
    {
    }
    return 0;
}
